package com.woniu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniu.entity.PageBean;
import com.woniu.entity.ProApprove;
import com.woniu.entity.Project;
import com.woniu.mapper.ProApproveMapper;
import com.woniu.mapper.ProjectMapper;
import com.woniu.service.IProApproveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
@Service
@Transactional
public class ProApproveServiceImpl extends ServiceImpl<ProApproveMapper, ProApprove> implements IProApproveService {
    @Autowired
    private ProApproveMapper proApproveMapper;
    @Override
    public PageBean<ProApprove> getByPage(ProApprove proApprove, int page,int pageSize) {
        PageBean<ProApprove> pageBean=new PageBean<>();
        Page<ProApprove> p= PageHelper.startPage(page,pageSize);//p
        List<ProApprove> data=proApproveMapper.getByCondition(proApprove);//data
        pageBean.setData(data);//data
        pageBean.setCurrPage(page);
        pageBean.setCurrPageSize(data.size());
        pageBean.setPageSize(pageSize);
        pageBean.setTotalNums((int)p.getTotal());//p
        pageBean.setTotalPages(p.getPages());

        return pageBean;
    }

    @Override
    public void add(ProApprove proApprove) {
proApproveMapper.add(proApprove);
    }

    @Override
    public List<ProApprove> getAll(){
        return proApproveMapper.getAll();
    };

    @Override
    public void update(ProApprove proApprove) {
proApproveMapper.update(proApprove);
    }

    @Override
    public ProApprove getByProApproveId(int approveId) {
        return proApproveMapper.getByProApproveId(approveId);
    }

    @Override
    public List<ProApprove> getProApproveByProId(int proId) {
        return proApproveMapper.getProApproveByProId(proId);
    }



    @Override
    public List<ProApprove> getByCondition(ProApprove proApprove) {
        return proApproveMapper.getByCondition(proApprove);
    }

    @Override
    public Integer getNumsByProStatusAndProId(Project project, String appProStatus) {
        return proApproveMapper.getNumsByProStatusAndProId(project,appProStatus);
    }

    @Override
    public List<ProApprove> getProApproveByProStatusAndProId(Project project, String appProStatus) {
        return proApproveMapper.getProApproveByProStatusAndProId(project,appProStatus);
    }

    //通过uid查找项目id，再查审批不通过的表
    @Override
    public List<ProApprove> findByUId(int uid) {
        return proApproveMapper.getByUid(uid);
    }

    @Override
    public ProApprove getProAppNotPassByProId(int proId) {
        return proApproveMapper.getProAppNotPassByProId(proId);
    }


    @Override
    public ProApprove getProAppProcessingByProId(int proId) {
        return proApproveMapper.getProAppProcessingByProId(proId);
    }

    //创建审批表
    @Override
    public void insertProApprove(ProApprove proApprove) {
        proApproveMapper.insertProApprove(proApprove);
    }

    //重新提交审批表
    @Override
    public void reSubmitProApprve(ProApprove proApprove) {
        proApproveMapper.reSubmitProApprve(proApprove);
    }


    //审核通过
    @Override
    public void Apass(int proid, String aatime, String afeedback) {
        proApproveMapper.Apass(proid,aatime,afeedback);
    }

    //审核通过
    @Override
    public void Aunpass(int approveId, String aatime, String afeedback) {
        proApproveMapper.Apass(approveId,aatime,afeedback);
    }


}
